home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / MacGzip 0.1b2 Source / gzip-1.2.4 sources / macos / think / SPDCProg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-08  |  6.9 KB  |  278 lines  |  [TEXT/KAHL]

  1. /*
  2.  * Copyright (C) 1993  SPDsoft
  3.  * 
  4.  */
  5.  
  6. #include "SPDProg.h"
  7. /*            SpinCursors by
  8.  *            America Online: LISPer
  9.  *             Internet: tree@uvm.edu
  10. */
  11. #define HiWrd(aLong)    (((aLong) >> 16) & 0xFFFF)
  12.  
  13. typedef struct                /* The structure of an 'acur' resource */
  14. {
  15.     short numberOfFrames;        /* number of cursors to animate */
  16.     short whichFrame;        /* current frame number */
  17.     CursHandle frame[];        /* Pointer to the first cursor */
  18. } acur, *acurPtr, **acurHandle;
  19.  
  20. unsigned long int    SPDBackCycles;
  21.  
  22. Boolean        UseAnimatedCursor=false;
  23. Boolean        CanBreak=false;
  24. acurHandle    gFrameList;
  25.  
  26. Boolean InitAnimatedCursors(short acurID)
  27. {
  28.     register short i=0;
  29.     register short cursID;
  30.     Boolean noErrFlag = FALSE;
  31.     SPDBackCycles=0;
  32.     
  33.     if((gFrameList = (acurHandle) GetResource('acur',acurID))) {
  34.         /* got it! */
  35.         noErrFlag = TRUE;
  36.         while((i<(*gFrameList)->numberOfFrames) && noErrFlag) {
  37.             /* The id of the cursor is stored in the high word of the frame handle */
  38.             cursID = (int) HiWrd((long) (*gFrameList)->frame[i]);
  39.             (*gFrameList)->frame[i] = GetCursor(cursID);
  40.             if((*gFrameList)->frame[i])
  41.                 i++;            /* get the next one */
  42.             else
  43.                 noErrFlag=FALSE;    /* foo! we couldn't find the cursor */
  44.         }
  45.     }
  46.     if(noErrFlag) {
  47.  
  48.         (*gFrameList)->whichFrame = 0;
  49.         UseAnimatedCursor=true;
  50.     }
  51.     return noErrFlag;
  52. }
  53.  
  54. /* Free up the storage used by the current animated cursor and all
  55.    of its frames */
  56. void ReleaseAnimatedCursors()
  57. {
  58.     int i;
  59.     
  60.     if(UseAnimatedCursor)
  61.     {
  62.         for(i=0;i<(*gFrameList)->numberOfFrames;i++)
  63.             ReleaseResource((Handle) (*gFrameList)->frame[i]);
  64.         ReleaseResource((Handle) gFrameList);
  65.     }
  66.     UseAnimatedCursor=false;
  67.     SetCursor(&arrow);
  68.  
  69. }
  70.  
  71. /************************************************************************************/
  72.  
  73. /* Opens the MModal dialog. */
  74. /* Just for grins, I'm also saving and restoring it's position in*/
  75. /* a very simple way */
  76.  
  77. void DrawMovable(WindowPtr drawIt);
  78. void UpdateBar(void);
  79.  
  80. Boolean    UseMModalProg=false;
  81.  
  82. static Rect        barRect; 
  83. static Rect        greyRect;
  84. static short int mypat[] = { 0x55AA,0x55AA,0x55AA,0x55AA };    /* Grey */
  85. unsigned long int SPDEnd, SPDNow;
  86.  
  87. Str255    SPDPstr="\p";
  88. char*    SPDpstr=(char*)SPDPstr;
  89.  
  90. static    Boolean        gModalUp;
  91. static    Boolean        gSavedPos;
  92. static    Point        gSavedPoint;
  93.  
  94. #define    kMyModalKind    1000
  95.  
  96. void InitMovableModal(unsigned long int theEnd)
  97. {
  98.     WindowPtr temp;
  99.  
  100.     temp = GetNewWindow(150, nil, (WindowPtr)-1);
  101.     /* install drawing proc */
  102.     SetWRefCon(temp, (long)DrawMovable);
  103.     
  104.     /* set the kind to my MModalwindow */
  105.     ((WindowPeek)temp)->windowKind = kMyModalKind;
  106.     gModalUp = true;
  107.     
  108.     if (gSavedPos) {
  109.         /* move it to the saved position */
  110.         /* move it to 0,0 to avoid any math at all */
  111.         MoveWindow(temp, 0, 0, false);
  112.         MoveWindow(temp, gSavedPoint.h, gSavedPoint.v, false);
  113.     }
  114.     
  115.     SPDNow=0;
  116.     SPDEnd=(theEnd==0?1:theEnd);
  117.  
  118.     UseMModalProg=true;
  119.     CtoPstr(SPDPstr);
  120.     
  121.     barRect.left=temp->portRect.left+20;
  122.     barRect.right=temp->portRect.right-20;
  123.     barRect.bottom=temp->portRect.bottom - 20;
  124.     barRect.top=barRect.bottom-20;
  125.     
  126.     greyRect.left=barRect.left+1;
  127.     greyRect.right=greyRect.left;
  128.     greyRect.bottom=barRect.bottom-1;
  129.     greyRect.top=barRect.top+1;
  130.     
  131.     ShowWindow(temp);
  132.  
  133.     SetPort(temp);
  134. }
  135.  
  136. void ReleaseMovableModal(void)
  137. {
  138.     WindowPtr temp = FrontWindow();
  139.  
  140.     if(UseMModalProg)
  141.     {
  142.         /* the front window really should be my modal window */
  143.         /* if it isn't, I'm bailing.*/
  144.         gSavedPos = true;
  145.         gSavedPoint.h = temp->portRect.left;
  146.         gSavedPoint.v = temp->portRect.top;
  147.         LocalToGlobal(&gSavedPoint);
  148.         if (((WindowPeek)temp)->windowKind == kMyModalKind)
  149.             CloseWindow(temp);
  150.     
  151.         gModalUp = false;
  152.         UseMModalProg=false;
  153.     }
  154. }
  155.  
  156. static void DrawMovable(WindowPtr drawIt)
  157. {
  158.     WindowPtr tempWP;
  159.     unsigned long int wbar;
  160.     Str255 stemp;
  161.  
  162.     BeginUpdate(drawIt);
  163.     GetPort(&tempWP);
  164.     SetPort(drawIt);
  165.     
  166.         MoveTo(20,20);/*h,v*/
  167.         DrawString(SPDPstr);
  168.  
  169.     wbar = SPDNow*(barRect.right-barRect.left)/SPDEnd+barRect.left; 
  170.     if ( wbar >= barRect.right ) wbar = barRect.right;
  171.     FrameRect(&barRect);
  172.     greyRect.right=wbar-1;
  173.     FillRect(&greyRect,mypat);
  174.  
  175.     DrawControls(drawIt);
  176.     EndUpdate(drawIt);
  177.     SetPort(tempWP);
  178. }
  179.  
  180. static void UpdateBar(void)
  181. {
  182.     WindowPtr tempWP,drawIt;
  183.     unsigned long int wbar;
  184.  
  185.     drawIt = FrontWindow();
  186.     GetPort(&tempWP);
  187.     SetPort(drawIt);
  188.     
  189.  
  190.     wbar = SPDNow*(barRect.right-barRect.left)/SPDEnd+barRect.left; 
  191.     if ( wbar >= barRect.right ) wbar = barRect.right;
  192.     FrameRect(&barRect);
  193.     greyRect.right=wbar-1;
  194.     FillRect(&greyRect,mypat);
  195.  
  196.     DrawControls(drawIt);
  197.     EndUpdate(drawIt);
  198.     SetPort(tempWP);
  199. }
  200.  
  201. /************************************************************************************/
  202.  
  203. Boolean    SPDSystemTask()
  204. {
  205.     typedef long (*MyProcPtr)();
  206.     
  207.     EventRecord    theEvent;
  208.     MyProcPtr    drawProc;
  209.     WindowPtr    twindow;
  210.     static unsigned long int TheLastTime;
  211.     
  212.     if(UseMModalProg)
  213.     {
  214.         SPDNow+=10;
  215.         UpdateBar();
  216.     }
  217. /*    SystemTask();*/
  218.     GetNextEvent(everyEvent, &theEvent);
  219.     {
  220.     if ((theEvent.what == keyDown)&&(CanBreak))
  221.     {
  222.         if (((theEvent.modifiers & cmdKey) != 0)
  223.         && ((theEvent.message & charCodeMask) == '.' ))
  224.         {
  225.             SetCursor(&arrow);
  226.             return(true);
  227.         }
  228.     }else if ((theEvent.what == updateEvt)&&(UseMModalProg))
  229.     {
  230.                 /* Mkae sure it's my window before I jump through the refCon */
  231.                 /* Why, since DA's have they're own layer in 7.0? */
  232.                 /* BECAUSE there are other people in the universe who will */
  233.                 /* add things to your windowList.BalloonWriter, for example, */
  234.                 /* so you still need to be careful */
  235.                 if (((WindowPeek)theEvent.message)->windowKind == kMyModalKind)
  236.                 {
  237.                     /* get the drawing proc from the refCon */
  238.                     drawProc = (MyProcPtr)GetWRefCon((WindowPtr)theEvent.message);
  239.                     /* jump to it */
  240.  
  241.                     drawProc((WindowPtr)theEvent.message);
  242.  
  243.                 }
  244.         }else if (theEvent.what == mouseDown)
  245.         {
  246.             switch (FindWindow(theEvent.where, &twindow))
  247.             {
  248.                 case inSysWindow:
  249.                                 /* pass to the system */
  250.                                 SystemClick(&theEvent, twindow);
  251.                                 break;
  252.                         case inDrag:
  253.                             if (twindow != FrontWindow() && gModalUp)
  254.                             {
  255.                             /* don't do anything, can't drag a back window */
  256.                                SysBeep(1);
  257.                             } else
  258.                             {
  259.                             DragWindow(twindow, theEvent.where, &qd.screenBits.bounds);
  260.                             }
  261.                             break;
  262.                         default:    break;
  263.  
  264.                 
  265.             }
  266.     }
  267.     
  268.     if(( theEvent.when-TheLastTime > kTicksCursor )&&(UseAnimatedCursor))
  269.     {
  270.         SetCursor(*((*gFrameList)->frame[(*gFrameList)->whichFrame++]));
  271.         if((*gFrameList)->whichFrame == (*gFrameList)->numberOfFrames)
  272.             (*gFrameList)->whichFrame = 0;
  273.             
  274.         TheLastTime=theEvent.when;
  275.     }
  276.     }
  277.     return(false);
  278. }